function onAlimentacionHabitualLoad(){
    initAlimentacionHabitualDetailUI();

    pacienteModel.removeIdChangedListener(pacienteEvaluacionSelect, evaluacionesModel);
    pacienteModel.removeIdChangedListener(pacienteRiesgoSelect, riesgosModel);
    pacienteModel.removeIdChangedListener(pacienteEvalClinicaSelect, evalClinicasModel);
    pacienteModel.removeIdChangedListener(pacienteFormulaDesarrolladaSelect, formulasDesarrolladasModel);
    pacienteModel.removeIdChangedListener(pacienteDetailSelect, pacienteDetailUI);
    pacienteModel.removeIdChangedListener(pacienteToleranciaSelect, toleranciaModel);

    pacienteModel.addIdChangedListener(pacienteAlimentacionHabitualSelect, alimentacionHabitualModel);
}

function pacienteAlimentacionHabitualSelect(id, context){
    alimentacionHabitualModel.idColumn.value = id;
    alimentacionHabitualModel.setColumnValue("AlimentacionHabitual", "paciente_id", id)

    alimentacionHabitualDetailUI.edit();
}

function initAlimentacionHabitualDetailUI(){
    alimentacionHabitualDetailUI = new DetailUI("Alimentación Habitual");

    alimentacionHabitualDetailUI.setModel(alimentacionHabitualModel);
    alimentacionHabitualDetailUI.setTitleContainer(document.getElementById("detail_title"));
    alimentacionHabitualDetailUI.setMessageContainer(document.getElementById("errorMessage"));

    alimentacionHabitualDetailUI.setOkButton(document.getElementById("sbtguardar"));

    alimentacionHabitualDetailUI.addField(document.getElementById("hora_desayuno"), "AlimentacionHabitual", "hora_desayuno", "string", 1, true);
    alimentacionHabitualDetailUI.addField(document.getElementById("desayuno"), "AlimentacionHabitual", "desayuno", "string", 1, true);

    alimentacionHabitualDetailUI.addField(document.getElementById("hora_almuerzo"), "AlimentacionHabitual", "hora_almuerzo", "string", 1, true);
    alimentacionHabitualDetailUI.addField(document.getElementById("almuerzo"), "AlimentacionHabitual", "almuerzo", "string", 1, true);

    alimentacionHabitualDetailUI.addField(document.getElementById("hora_merienda"), "AlimentacionHabitual", "hora_merienda", "string", 1, true);
    alimentacionHabitualDetailUI.addField(document.getElementById("merienda"), "AlimentacionHabitual", "merienda", "string", 1, true);

    alimentacionHabitualDetailUI.addField(document.getElementById("hora_cena"), "AlimentacionHabitual", "hora_cena", "string", 1, true);
    alimentacionHabitualDetailUI.addField(document.getElementById("cena"), "AlimentacionHabitual", "cena", "string", 1, true);

    alimentacionHabitualDetailUI.addField(document.getElementById("hora_colacion_1"), "AlimentacionHabitual", "hora_colacion_1", "string", 1, true);
    alimentacionHabitualDetailUI.addField(document.getElementById("hora_colacion_2"), "AlimentacionHabitual", "hora_colacion_2", "string", 1, true);
    alimentacionHabitualDetailUI.addField(document.getElementById("colacion"), "AlimentacionHabitual", "colacion", "string", 1, true);


    alimentacionHabitualModel.idColumn.value = pacienteModel.idColumn.value;
    alimentacionHabitualModel.setColumnValue("AlimentacionHabitual", "paciente_id", pacienteModel.idColumn.value)

    $(".time").timepicker({
        hourText: 'Hora',
        minuteText: 'Minutos'
    });

    $(".time").attr("readonly", "readonly")

    alimentacionHabitualDetailUI.edit();

    $("#btnReporte").button();
    $("#btnReporte").click(mostrarReporteHabitual);

}

function mostrarReporteHabitual(){
    $("#divReporteHabitual").load(
    webRoot+"AlimentacionHabitual/getReport/"+pacienteModel.idColumn.value+"/"+Math.random(),
    function(){
        $("#divReporteHabitual").dialog({
            width: 680,
            height: 400
        });
    });
}
